<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link href="css/style.css" rel="stylesheet" type="text/css"/>
    <link href="css/select.css" rel="stylesheet" type="text/css"/>
    <script type="text/javascript" src="js/jquery-1.8.2.min.js"></script>
    <script type="text/javascript" src="js/jquery.idTabs.min.js"></script>
    <script type="text/javascript" src="js/select-ui.min.js"></script>
    <script type="text/javascript" src="editor/kindeditor.js"></script>
    <script type="text/javascript" src="js/jquery.params.js"></script>

    <script type="text/javascript">
        KE.show({
            id: 'content7',
            cssPath: './index.css'
        });
    </script>

    <script type="text/javascript">
        $(document).ready(function (e) {
            $(".select1").uedSelect({
                width: 345
            });
            $(".select2").uedSelect({
                width: 167
            });
            $(".select3").uedSelect({
                width: 100
            });
        });
        $.ajax({
            url:'/admin/stock/findBorrowed',
            data:JSON.stringify(""),
            type:'POST',
            dataType:'json',
            /*
           声明参数位json类型，便于后台接收时可以识别
            */
            headers:{
                Accept:"application/json",
                "Content-Type":"application/json"
            },
            processData:false,
            cache:false
        }).done(function (data) {
            //alert(data);
            getBorrowedList(data.fixlogs);
        });
        function getBorrowedList(borrowedList) {
            var borrowedListInHTML="";
            for (var i in borrowedList){
                borrowedListInHTML+=
                    "                    <tr>" +
                    "                        <td><input name=\"id\" type=\"checkbox\" value=\""+borrowedList[i].id+"\" /></td>\n" +
                    "                        <td>"+borrowedList[i].id+"</td>\n" +
                    "                        <td>"+borrowedList[i].workername+"</td>\n" +
                    "                        <td>"+borrowedList[i].username+"</td>\n" +
                    "                        <td>"+borrowedList[i].toolname+"</td>\n" +
                    "                        <td>"+borrowedList[i].partsname+"-共"+borrowedList[i].partscount+"个</td>\n" +
                    "                        <td><a href=\"/itemreturn.html?fixLogId="+borrowedList[i].id+"\" class=\"tablelink\">归还工具并记录旧件信息</a>\n" +
                    "                    </tr>";
            }
            $("#itemReturnList").html(borrowedListInHTML);
        }
        function verifyAndSubmit() {
            var params=$("#itemForm").serializeArray();
            var itemInfo={};
            var errorIndex;
            for (var item in params){
                if (params[item].value == null || params[item].value == ""){
                    errorIndex=params[item].name;
                    alert(getError(errorIndex)+"不得为空！");
                    return  ;
                }else{
                    itemInfo[params[item].name]=params[item].value;
                }
            }
            alert(JSON.stringify(itemInfo));
            $.ajax({
                url:'/admin/stock/itemStorage',
                data:JSON.stringify(itemInfo),
                type:'POST',
                dataType:'json',
                /*
               声明参数位json类型，便于后台接收时可以识别
                */
                headers:{
                    Accept:"application/json",
                    "Content-Type":"application/json"
                },
                processData:false,
                cache:false
            }).done(function (data) {
               alert("添加成功！");
            });
        }
        function getError(errorIndex) {
            switch (errorIndex) {
                case "name": return "补货物品名称";break;
                case "use": return "补货物品用途";break;
                case "count": return "补货物品数量";break;
                case "price": return "补货物品价格";break;
            }
        }
    </script>
</head>

<body>

<div class="place">
    <span>位置：</span>
    <ul class="placeul">
        <li><a href="#">首页</a></li>
        <li><a href="#">系统设置</a></li>
    </ul>
</div>

<div class="formbody">


    <div id="usual1" class="usual">

        <div class="itab">
            <ul>
                <li><a href="#tab1" class="selected">仓库补货</a></li>
                <li><a href="#tab2">工人归还</a></li>
            </ul>
        </div>

        <div id="tab1" class="tabson">
            <form id="itemForm">
                <ul class="forminfo" id="itemInfo" >
                    <li><label>名称<b>*</b></label><input name="name" type="text" value="" class="dfinput" placeholder="请输入补货物品的名称"
                                                        style="width:518px;"/></li>
                    <li><label>类型<b>*</b></label>

                        <div class="vocation">
                            <select class="select1" name="type">
                                <option value="0">工具</option>
                                <option value="1">产品配件</option>
                            </select>
                        </div>
                    </li>
                    <li><label>用途<b>*</b></label><input name="use" value="" type="text" class="dfinput"
                                                        style="width:518px;"/></li>
                    <li><label>数量<b>*</b></label><input name="count" type="number" value="" class="dfinput"
                                                        placeholder="请输入补货物品的数量" style="width:518px;"/>
                    </li>
                    <li><label>价格<b>*</b></label><input name="price" type="number" value="" class="dfinput"
                                                        style="width:518px;"/></li>
                    <li><label>注意<b></b></label><font class="dfinput">请注意检验每件物品是否正常使用</font></li>

                    <li><label>&nbsp;</label><input onclick="verifyAndSubmit();" type="button" class="btn" value="入库"/></li>
                </ul>
            </form>
        </div>
        <div id="tab2" class="tabson">
            <table class="tablelist">
                <thead>
                <tr>
                    <th><input name="" type="checkbox" value="" checked="checked"/></th>
                    <th>编号<i class="sort"><img src="images/px.gif" /></i></th>
                    <th>工人姓名</th>
                    <th>工人工号</th>
                    <th>借走工具</th>
                    <th>借走零件</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody id="itemReturnList">

                </tbody>
            </table>

        </div>


    </div>

    <script type="text/javascript">
        $("#usual1 ul").idTabs();
    </script>

    <script type="text/javascript">
        $('.tablelist tbody tr:odd').addClass('odd');
    </script>


</div>

</body>
</html>